package middleware

import (
	"mime/multipart"
	"net/http"

	"gddgame.cc/galaxy/utils/def"
)

type Next func(err error) error
type Handler func(context Context, next Next) error

//func Handle(middle Handler) func(http.Handler) http.Handler {
//	return func(next http.Handler) http.Handler {
//		h := func(writer http.ResponseWriter, request *http.Request) {
//			next.ServeHTTP(writer, request)
//		}
//		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
//			middle(h, w, r)
//		})
//	}
//}

type Context interface {
	def.Context

	Request() *http.Request
	Writer() http.ResponseWriter
	IsClose() bool
	Reset()
	PathParam(key string) string
	GetParam(key string) (string, error)
	GetParamArray(key string) ([]string, error)
	GetParamMap(key string) (map[string][]string, error)
	PostParam(key string) (string, error)
	PostParamArray(key string) ([]string, error)
	PostParamMap(key string) (map[string][]string, error)
	Header(key string) string
	Cookie(key string) (*http.Cookie, error)
	FormFile(key string) (multipart.File, *multipart.FileHeader, error)
	BodyJson(s interface{}) error
	SetResponse(s interface{})
	GetResponse() interface{}

	SetLogger(logger def.Logger)
	SetStore(store def.Store)
	SetID(id string)
}
